package com.wang.gateway.userHi;

import com.wang.api.Interface.SayHi;
import com.wang.api.Interface.Service;
import com.wang.api.userInfo.UserRequest;
import com.wang.api.userInfo.UserResponse;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class HiClient implements CommandLineRunner {

    @DubboReference
    private SayHi sayHi;

    @DubboReference
    private Service<UserRequest, UserResponse> service;


    @Override
    public void run(String... args) {
        new Thread(() -> {
            int flag = 0;
            UserRequest request = new UserRequest();
            request.setName("dob");
            request.setAge("22");
            UserResponse response = service.execute(request);
            System.out.println("userResponse===> " +response.toString());
            while (flag < 5) {
                try {
                    flag++;
                    Thread.sleep(1000);
                    System.out.println(new Date() + "sayHi result======>" + sayHi.sayHi("Doto"));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                }
            }
        }).start();
    }
}
